package jdbc;

import entity.User;
import util.JdbcUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

/**
 * @author Ashin0013
 * @Date 2020/1/5 21:46
 */
class jdbcUtilsTest {
    public void jdbcTest() throws SQLException {
        Connection con = JdbcUtils.getConnection();
        Statement s = con.createStatement();
        ResultSet re = s.executeQuery("select * from users WHERE id=434397625 AND password=123456");
        while (re.next()) {
            System.out.println(re.getString("motto"));
        }
    }

    public void loginTest() throws Exception {
        Function f = new Function();
        User user = new User("4343976", "123456", "Cshin");
        int num = f.login(user);
        System.out.println(num);
    }

    public void insertTest() throws Exception {
        Function f = new Function();
        User user = new User("434397", "123456", "Dshin");
        if (f.insert(user)) {
            System.out.println("1");
        } else {
            System.out.println("0");
        }
    }

    public void isIdExistTest() {
        Function f = new Function();
        if (f.isIdExist("434397625")) {
            System.out.println(1);
        } else {
            System.out.println(2);
        }
    }

    public void dataInsertTest() {
        Function f = new Function();
        if (f.insertPrivateChatData("Ashin", "2", "hello")) {
            System.out.println("1");
        } else {
            System.out.println("0");
        }
    }

    public void dataGetTest() throws SQLException {
        Function f = new Function();
        System.out.println(f.getPrivateChatRecord("Ashin", "2"));

    }


    public void FindTest(){
        Function f = new Function();
        User user = f.findUser("434397625");
        System.out.println(user.getPassword());
    }

    public void update(){
        Function f = new Function();
        User u = new User("434397625","haha","Ashin0013","19","男","北京","13333","123456");
        f.update(u);
        User us = f.findUser("434397625");
        System.out.println(us.getTelNum());
    }

    public void IdTest(){
        Function f = new Function();
        ArrayList<String> a = f.getAllId();
        System.out.println(a.toString());
    }

    public void groupDataInsertTest(){
        Function f = new Function();
        f.insertGroupChatRecord("2","nmsl");
    }

    public void groupDataFindTest() throws SQLException {
        Function f = new Function();
        ArrayList<String> a = new ArrayList<>();
        a =f.getGroupChatRecord("2");
        System.out.println(a.toString());
    }
    public static void main(String[] args) throws Exception {
        jdbcUtilsTest j = new jdbcUtilsTest();
        j.groupDataInsertTest();
        j.groupDataFindTest();
    }
}